#!/bin/bash
OK=0
WARN=1
CRITICAL=2
UNKNOWN=3
PATH="/bin:/sbin:/usr/bin:/usr/sbin"

Ok_name=''
Fail_name=''
Judge=0
TTimeout=5
#HName=`/bin/hostname -s`

function timeout_df() {
		#echo $choice start
                #/usr/bin/timeout 1 /usr/lib64/nagios/plugins/check_mount_strace touch /$2 1>/dev/null 2>&1   #touch a new file, if not exist
                /usr/bin/timeout $TTimeout strace test -$1 /$2 1>/dev/null 2>&1
		#continue

                if [ $? != 0  ]
                then
                        Judge=1
                        Fail_name="${Fail_name} ${choice}"
		else
			Ok_name="${Ok_name} ${choice}"
                fi
		#echo $choice end
}




Test_mount="$1"
#Lmount=`cat /etc/init.d/lustre  |grep "nms check"|awk -F : '{print $2}'`
#for choice in besfs bes3fs publicfs besfs2 dybfs scratchfs workfs cefs             
        ###
for choice in $Test_mount
do
	case $choice in
        workfs)
		timeout_df  r "$choice/cc/nagios/testfs" 
                ;;

        besfs3)
                timeout_df  w "$choice/nms/$HName"
                ;;

        acfs)
                timeout_df  w "$choice/nms/$HName"
                ;;

        junofs)
                timeout_df  w "$choice/nms/$HName"
                ;;

        *)
                timeout_df  w "$choice/nms/testfs"
                ;;



	esac

done

if [ $Judge -eq 1 ]
then
	echo "$Fail_name  wrong, can not write or read"
	exit $CRITICAL
else
	echo " $Ok_name are OK, can write or read "
	exit $OK
fi

